from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class ExamPage:
    def __init__(self, driver):
        self.driver = driver

    def find_questions(self):
        xpath = '//*[@class="question_warp"]'
        elems = WebDriverWait(self.driver, 10).until(
            EC.presence_of_all_elements_located((By.XPATH, xpath)))
        return elems

    def find_title(self, elem):  # xpath_elem = '//*[@class="question_warp"]'
        xpath = 'h3'
        elem = elem.find_element(By.XPATH, xpath)
        return elem

    def find_options(self, elem):
        xpath = 'div/div/label'
        elems = elem.find_elements(By.XPATH, xpath)
        return elems

    def find_answer(self, elem):
        xpath = 'div/p/strong[1]'
        elem = elem.find_element(By.XPATH, xpath)
        return elem

    def find_submit(self):
        xpath = '/html/body/form/div[2]/div[5]/button'
        elem = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH, xpath)))
        return elem

    def find_exam_again(self):
        xpath = '/html/body/div[3]/div[4]/button'
        elem = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH, xpath)))
        return elem

    def find_confirm(self):
        xpath = '/html/body/div[2]/div[3]/a[1]'
        elem = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH, xpath)))
        return elem
